package com.hello.system.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.hello.common.log.annotation.Log;
import com.hello.common.log.enums.BusinessType;
import com.hello.common.security.annotation.RequiresPermissions;
import com.hello.system.domain.RentalNotifications;
import com.hello.system.service.IRentalNotificationsService;
import com.hello.common.core.web.controller.BaseController;
import com.hello.common.core.web.domain.AjaxResult;
import com.hello.common.core.utils.poi.ExcelUtil;
import com.hello.common.core.web.page.TableDataInfo;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

/**
 * 消息通知Controller
 * 
 * @author hello
 * @date 2025-07-20
 */
@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/notifications")
public class RentalNotificationsController extends BaseController
{
    private final IRentalNotificationsService rentalNotificationsService;

    /**
     * 查询消息通知列表
     */
    // @RequiresPermissions("system:notifications:list")
    @GetMapping("/list")
    public TableDataInfo list(RentalNotifications rentalNotifications)
    {
        log.info("======== 查询消息通知列表请求 ========");
        log.info("请求参数: {}", rentalNotifications);
        
        startPage();
        List<RentalNotifications> list = rentalNotificationsService.selectRentalNotificationsList(rentalNotifications);
        TableDataInfo result = getDataTable(list);
        
        log.info("查询结果: 总记录数={}, 当前页数据量={}", result.getTotal(), list.size());
        log.info("======== 查询消息通知列表完成 ========");
        
        return result;
    }

    /**
     * 导出消息通知列表
     */
    // @RequiresPermissions("system:notifications:export")
    @Log(title = "消息通知", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RentalNotifications rentalNotifications)
    {
        log.info("======== 导出消息通知数据请求 ========");
        log.info("导出条件: {}", rentalNotifications);
        
        List<RentalNotifications> list = rentalNotificationsService.selectRentalNotificationsList(rentalNotifications);
        log.info("导出数据量: {} 条记录", list.size());
        
        ExcelUtil<RentalNotifications> util = new ExcelUtil<RentalNotifications>(RentalNotifications.class);
        util.exportExcel(response, list, "消息通知数据");
        
        log.info("======== 消息通知数据导出完成 ========");
    }

    /**
     * 获取消息通知详细信息
     */
    // @RequiresPermissions("system:notifications:query")
    @GetMapping(value = "/{notificationId}")
    public AjaxResult getInfo(@PathVariable("notificationId") Long notificationId)
    {
        log.info("======== 获取消息通知详情请求 ========");
        log.info("通知ID: {}", notificationId);
        
        RentalNotifications notification = rentalNotificationsService.selectRentalNotificationsByNotificationId(notificationId);
        log.info("查询结果: {}", notification != null ? "找到通知信息" : "未找到对应通知");
        
        log.info("======== 获取消息通知详情完成 ========");
        return success(notification);
    }

    /**
     * 新增消息通知
     */
    // @RequiresPermissions("system:notifications:add")
    @Log(title = "消息通知", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RentalNotifications rentalNotifications)
    {
        log.info("======== 新增消息通知请求 ========");
        log.info("新增数据: {}", rentalNotifications);
        
        int result = rentalNotificationsService.insertRentalNotifications(rentalNotifications);
        log.info("新增结果: {}", result > 0 ? "成功" : "失败");
        
        log.info("======== 新增消息通知完成 ========");
        return toAjax(result);
    }

    /**
     * 修改消息通知
     */
    // @RequiresPermissions("system:notifications:edit")
    @Log(title = "消息通知", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RentalNotifications rentalNotifications)
    {
        log.info("======== 修改消息通知请求 ========");
        log.info("修改数据: {}", rentalNotifications);
        
        int result = rentalNotificationsService.updateRentalNotifications(rentalNotifications);
        log.info("修改结果: {}", result > 0 ? "成功" : "失败");
        
        log.info("======== 修改消息通知完成 ========");
        return toAjax(result);
    }

    /**
     * 删除消息通知
     */
    // @RequiresPermissions("system:notifications:remove")
    @Log(title = "消息通知", businessType = BusinessType.DELETE)
	@DeleteMapping("/{notificationIds}")
    public AjaxResult remove(@PathVariable Long[] notificationIds)
    {
        log.info("======== 删除消息通知请求 ========");
        log.info("删除通知ID列表: {}", java.util.Arrays.toString(notificationIds));
        log.info("删除数量: {} 个通知记录", notificationIds.length);
        
        int result = rentalNotificationsService.deleteRentalNotificationsByNotificationIds(notificationIds);
        log.info("删除结果: {}", result > 0 ? "成功" : "失败");
        
        log.info("======== 删除消息通知完成 ========");
        return toAjax(result);
    }
}
